//package com.cdtu.labpreview.config;
//
//import com.alibaba.druid.util.StringUtils;
//import com.google.common.collect.Lists;
//import org.springframework.boot.web.servlet.FilterRegistrationBean;
//import org.springframework.context.annotation.Bean;
//import org.springframework.stereotype.Component;
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//
//@Component
//public class crispFilter implements Filter {
//
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//        Filter.super.init(filterConfig);
//    }
//
//    @Bean(name = "corsFilter")
//    public FilterRegistrationBean corsFilter() {
//        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
//        registrationBean.setFilter(corsFilterBean());
//        registrationBean.setUrlPatterns(Lists.newArrayList("/*"));
//        registrationBean.setOrder(1);
//        return registrationBean;
//    }
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
////        HttpServletRequest request = (HttpServletRequest)servletRequest;
////        HttpServletResponse response = (HttpServletResponse) servletResponse;
////        System.out.println("跨域请求过滤器启动");
////        if (request.getRequestURL().toString().matches(".+.ico$")) {
////            filterChain.doFilter(servletRequest, servletResponse);
////        } else {
////            String origin = request.getHeader("Origin");
////            // 简单请求跨域，如果是跨域请求在响应头里面添加对应的Origin
////            if (!StringUtils.isEmpty(origin)) {
////                response.addHeader("Access-Control-Allow-Origin", "http://localhost:8081");
////            }
////            // 非简单请求跨域
////            response.addHeader("Access-Control-Allow-Headers", "content-type");
////            // 允许跨域请求的方法
////            response.addHeader("Access-Control-Allow-Methods", "*");
////            // 携带cookie的跨域
////            response.addHeader("Access-Control-Allow-Credentials", "true");
////
////            // 放行方法
////            filterChain.doFilter(servletRequest, servletResponse);
////        }
//    }
//
//    @Override
//    public void destroy() {
//        Filter.super.destroy();
//    }
//}
